﻿// -------------------------------------------------------------------------
//    @FileName         :    NFPayPart.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFPayPart
//
// -------------------------------------------------------------------------

#include "NFPayPart.h"

#include "proto_cs_login.pb.h"
#include "proto_db.pb.h"

NFPayPart::NFPayPart()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFPayPart::~NFPayPart()
{
}

int NFPayPart::CreateInit()
{
    m_account_toalpay = 0;
    return 0;
}

int NFPayPart::ResumeInit()
{
    return 0;
}

int NFPayPart::LoadFromDB(const proto_ff::tbRoleDetail* pDBData)
{
    m_stData.FromPb(pDBData->role_fortune_data().pay_data());
    return 0;
}

int NFPayPart::InitConfig(proto_ff::tbRoleDetail* pDbData, const RoleOne& stRoleOne)
{
    CHECK_NULL(0, pDbData);
    auto pRolePayData = pDbData->mutable_role_fortune_data()->mutable_pay_data();
    CHECK_NULL(0, pRolePayData);
    proto_ff::WeekConsumeData* pWeekConsumeData = pRolePayData->mutable_week_consume_data();
    CHECK_NULL(0, pWeekConsumeData);

    pWeekConsumeData->set_last_time(NF_ADJUST_TIMENOW());

    /*int iServerOpenTime = CServerUtil::GameSvrConfig()->GetServerOpenTime();
    int iGroupID = CDescUtil::GetDescStoreFirstPayAward()->GetGroupID(iServerOpenTime, NF_ADJUST_TIMENOW());
    pRolePayData->set_first_pay_group(iGroupID);

    int iActivityGroup = CDescUtil::GetDescStoreFirstPayAward()->GetActivityGroupID(iServerOpenTime, NF_ADJUST_TIMENOW());
    pRolePayData->set_fp_activity_group(iActivityGroup);

    LOGSVR_TRACE("groupid:" << iGroupID << ", ActivityGroupID:" << iActivityGroup);*/
    return 0;
}

int NFPayPart::SaveDB(proto_ff::tbRoleDetail* pDBData)
{
    m_stData.ToPb(pDBData->mutable_role_fortune_data()->mutable_pay_data());
    return 0;
}

int NFPayPart::MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp)
{
    auto pRolePayData = pCSGetRoleRsp->mutable_pay_data();
    pRolePayData->set_diamond(GetDiamond());
    pRolePayData->set_first_pay_state(GetFirstPaystate());
    pRolePayData->set_first_pay_group(GetFirstPayGroup());
    pRolePayData->set_total_account_pay(m_account_toalpay);

    m_stData.pay_award_data.ToPb(pRolePayData->mutable_pay_award_data());
    m_stData.week_consume_data.ToPb(pRolePayData->mutable_week_consume_data());
    m_stData.luck_bag_info.ToPb(pRolePayData->mutable_luck_bag_info());
    return 0;
}

int NFPayPart::MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo)
{
    return 0;
}

int NFPayPart::GetFirstPaystate()
{
    if (m_stData.fp_activity_group > 0)
    {
        return m_stData.fp_activity_state;
    }

    return m_stData.first_pay_state;
}

int NFPayPart::GetFirstPayGroup()
{
    return m_stData.fp_activity_group > 0 ? m_stData.fp_activity_group : m_stData.first_pay_group;
}
